In this Letter, we derive an effective theory of graphene on a hexagonal Boron Nitride (h-BN) substrate. We show that the h-BN substrate generically opens a spectral gap in graphene despite the lattice mismatch. The origin of that gap is particularly intuitive in the regime of strong coupling between graphene and its substrate, when the low-energy physics is determined by the topology of a network of zero energy modes. For twisted graphene bilayers, where inversion symmetry is present, this network percolates through the system and the spectrum is gapless. The breaking of that symmetry by h-BN causes the zero energy modes to close into rings. The eigenstates of these rings hybridize into flat bands with gaps in between. The size of this band gap can be tuned by a gate voltage and it can reach the order of magnitude needed to confine electrons at room temperature.